import { Router } from 'express'
import { authenticateToken as auth } from '@/middleware/auth'
import { AlbumsController } from '@/controllers/albums'
import { body } from 'express-validator'
import validateRequest from '@/middleware/validateRequest'

const router = Router()
const controller = new AlbumsController()

// 相册
router.get('/', auth, controller.listAlbums)
router.post('/',
  auth,
  [ body('title').isString().isLength({ min: 1 }).withMessage('标题必填') ],
  validateRequest,
  controller.createAlbum
)
router.patch('/:id', auth, controller.updateAlbum)
router.delete('/:id', auth, controller.deleteAlbum)

// 照片
router.get('/:albumId/photos', auth, controller.listPhotos)
router.post('/:albumId/photos', auth, controller.uploadPhoto)
router.delete('/photos/:id', auth, controller.deletePhoto)
router.post('/photos/:id/like', auth, controller.toggleLike)

export { router as albumsRoutes }
export default router